{include file="public/header" /}


<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>自定义菜单</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->
            <div class="row">
                <div class="col-sm-12">
                    <div  class="col-sm-2" style="width: 100px">
                        <div class="input-group" >
                            <a href="{:url('menu_add')}"><button class="btn btn-outline btn-primary" type="button">添加菜单</button></a>
                        </div>

                    </div>
                    <div  class="col-sm-5" style="width: 100px">
                    <div class="input-group" >


                        <a href="javascript:;" onclick="uptoweixin();return false;"><button class="btn btn-outline btn-primary" type="button">向微信公众平台同步</button></a>
                    </div>
                        </div>



                </div>
            </div>
            <!--搜索框结束-->
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="table table-bordered table-hover">
                        <thead>
                        <tr class="long-tr">
                            <th>菜单名称</th>
                            <th>类型</th>
                            <th width="15%">类型值</th>
                            <th width="15%">添加子菜单</th>
                            <th width="20%">操作</th>
                        </tr>
                        </thead>
                        <tbody id="article_list">
                        {foreach name="list" item="vo"}
                        <tr class="long-td" id="jl{$vo.id}">
                            <td style="text-align: left;padding-left: 100px;">{$vo.name}</td>
                            <td>{$vo.type}</td>
                            <td>{$vo.value}</td>
                            <td>
                                {if condition='$vo.pid ==0'}
                                <a href="{:url('wechat/menu_add',array('pid'=>$vo.id))}" class="btn btn-primary btn-xs">
                                <i class="fa fa-plus"></i></a>
                                {else}
                                &nbsp;
                                {/if}
                            </td>
                            <td>
                                <a href="javascript:;" onclick="menuurl({$vo.id})" class="btn btn-primary btn-xs">
                                    <i class="fa fa-trash-o"></i> 编辑</a>
                                <a href="javascript:;" onclick="menudel({$vo.id})" class="btn btn-danger btn-xs">
                                    <i class="fa fa-trash-o"></i> 删除</a>

                            </td>
                        </tr>

                        {foreach name="vo.son" item="vvv"}
                            <tr class="long-td" id="jl{$vvv.id}">
                                <td style="text-align: left;padding-left: 130px;">------{$vvv.name}</td>
                                <td>{$vvv.type}</td>
                                <td>{$vvv.value}</td>
                                <td></td>
                                <td>
                                    <a href="javascript:;" onclick="menuurl({$vvv.id})" class="btn btn-primary btn-xs">
                                        <i class="fa fa-trash-o"></i> 编辑</a>
                                    <a href="javascript:;" onclick="menudel({$vvv.id})" class="btn btn-danger btn-xs">
                                        <i class="fa fa-trash-o"></i> 删除</a>
                                </td>
                            </tr>
                         {/foreach}



                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>
{include file="public/footer" /}


<script type="text/javascript">

    /**
     * [del 删除用户]
     * @Author[沈晶晶 334554156@qq.com]
     * @param   {[type]}    id [用户id]
     */
    //    function del_cate(id){
    //        layer.confirm('确认删除此机构?', {icon: 3, title:'提示'}, function(index){
    //            //do something
    //            $.getJSON('./del_cate', {'id' : id}, function(res){
    //                if(res.code == 1){
    //                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
    //                        window.location.href="{:url('article/index_cate')}";
    //                    });
    //                }else{
    //                    layer.msg(res.msg,{icon:0,time:1500,shade: 0.1});
    //                }
    //            });
    //
    //            layer.close(index);
    //        })
    //
    //    }


//删除用户
    function menudel(id){


        layer.confirm('确认删除此条记录吗?', {icon: 3, title:'提示'}, function(index){
            $.post('{:url("wechat/menu_del")}', {id:id}, function(data){
                console.log(data);
                  if(data.code==1){
                      layer.msg(data.msg,{icon:1,time:1500,shade: 0.1});
                      var ccc= '#jl'+id;
                      $(ccc).remove();
                  }else{
                      layer.msg(data.msg,{icon:5,time:1500,shade: 0.1});
                  }
                layer.close(index);
            });
        })



    }


    function uptoweixin(){
        $.post('{:url("wechat/pub_menu")}', {}, function(data){
            var v =  eval('('+data+')');
            if(v.errcode==0){
                layer.msg('同步成功',{icon:6,time:1500,shade: 0.1});
            }else{
                layer.msg('同步失败，错误代码:'+v.errcode,{icon:5,time:1500,shade: 0.1});
            }

        });
    }

    function menuurl(id){
        location.href = '/admin/wechat/menu_edit/id/'+id+'.html';
    }


</script>
</body>
</html>